package com.mgq.algorithm.link;

/**
 * @author MaGuangQi
 *
 * @date 2021-12-31 11:54
 **/
public class MiddleLinkedList_876 {

    /**
     * 快慢指针. 快指针走2步,慢指针走1步.
     * 当快指针到最后时,慢指针刚好到中间
     * @param head
     * @return
     */
    public ListNode middleNode(ListNode head) {
        ListNode slow=head;
        ListNode fast=head;
        while (fast != null&&fast.next!=null) {
            slow=slow.next;
            fast=fast.next.next;
        }
        return slow;
    }
}
